package com.wei.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wei.model.BrandDO;
import com.wei.model.ProductDO;
import com.wei.result.R;
import com.wei.service.IBrandService;
import com.wei.service.IProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/brand")
@CrossOrigin(origins = "*")
@RequiredArgsConstructor
@Api(tags = "品牌管理")
public class BrandController {

    private final IBrandService brandService;

    private final IProductService productService;

    @ApiOperation("获取所有品牌列表")
    @GetMapping("/listAll")
    public R<List<BrandDO>> getAllBrands() {
        List<BrandDO> brandList = brandService.listAllBrands();
        return R.ok(brandList);
    }

    @GetMapping("/getProductByBrandId/{brandId}")
    public R<List<ProductDO>> findAll(@PathVariable("brandId") String brandId) {
        LambdaQueryWrapper<ProductDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ProductDO::getBrandId, brandId);
        List<ProductDO> productList = productService.list(queryWrapper);
        return R.ok(productList);
    }
}
